
const data = new Date()
// console.log(data.toLocaleString())
// console.log("获取年份:" + data.getFullYear())
// console.log("获取月份:" + (data.getMonth() + 1))
// console.log("获取星期:" + data.getDay())
// console.log("获取日期:" + data.getDate())
// console.log("获取小时:" + data.getHours())
// console.log("获取分钟:" + data.getMinutes())
// console.log("获取秒:" + data.getSeconds())
// const years = data.getFullYear()
// const month = data.getMonth() + 1 > 10 ? data.getMonth() + 1 : '0' + data.getMonth()
// const day = data.getDate()
// const hours = data.getHours() > 10 ? data.getHours() : '0' + data.getHours()
// const minutes = data.getMinutes() > 10 ? data.getMinutes() : '0' + data.getMinutes()
// console.log("YYYY-MM-DD HH:mm"+" "+years+'-'+month+'-'+day+" "+hours+":"+minutes)
// console.log("获取时间戳1：" + data.getTime())
// console.log("获取时间戳2：" + (+new Date()))
// console.log("获取时间戳3：" + Date.now())

setInterval(() => {
    // 获取现在的时间戳
    const nowDate = +new Date()
    // 获取截至的时间戳
    const endDate = +new Date(2024, 10, 7, 12, 00, 0)
    const freeDate = (endDate - nowDate) / 1000
    let day = parseInt(freeDate / 60 / 60 / 24)//计算天数
    let hours = parseInt(freeDate / 60 / 60 % 24)//计算小时
    let minutes = parseInt(freeDate / 60 % 60)//计算分钟
    let seconds = parseInt(freeDate % 60)//计算秒
    day = day ? '' : day
    hours = hours > 10 ? hours : "0" + hours
    minutes = minutes > 10 ? minutes : "0" + minutes
    seconds = seconds > 10 ? seconds : "0" + seconds
    console.log("距离中午吃饭还剩" + `${day}天${hours}小时${minutes}分钟${seconds}秒`);
}, 1000)

